#pragma once
#include "uart/ProtocolSender.h"
#include "water/cartridge_life.h"
#include "uart/ProtocolCustom.h"
#include "global_variables.h"
//打印信息是否开启标志位
//Global::Flags::IsCodeFalg;

static std::string PassWard="20190308";
//用户输入密码
static std::string PassWardUser="";
static SProtocolData datas;
//滤芯图标正在闪烁
bool FlagLvxin = false;
/**
 * 注册定时器
 * 填充数组用于注册定时器
 * 注意：id不能重复
 */
static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
	//{0,  6000}, //定时器id=0, 时间间隔6秒
//	{1,  500},
};




/**
 * 当界面构造时触发
 */
static void onUI_init(){
    //Tips :添加 UI初始化的显示代码到这里,如:mText1Ptr->setText("123");
//	getProtocolData().A1Byte1.byte=0x00;
//	getProtocolData().A1Byte2.byte=0x00;
//	getProtocolData().A1Byte3.byte=0x00;
//	getProtocolData().WaterOutlet=0x00;
//	getProtocolData().WaterTemp=0x00;
//	getProtocolData().Yield=0x00;
	PassWardUser="";
	mWindow1Ptr->showWnd();
}
//字符串添加
static void AddStr(std::string p){
	PassWardUser+=p;
	mTextView17Ptr->setText(PassWardUser);
}
//删除字符串
static void DelStr(){
	if(PassWardUser.size() >0){
		PassWardUser=PassWardUser.substr(0, PassWardUser.length()-1);
	}
	mTextView17Ptr->setText(PassWardUser);
}

/**
 * 当切换到该界面时触发
 */
static void onUI_intent(const Intent *intentPtr) {
    if (intentPtr != NULL) {
        //TODO
    }
}

/*
 * 当界面显示时触发
 */
static void onUI_show() {
	//隐藏左侧窗口
	//隐藏右侧窗口
}

/*
 * 当界面隐藏时触发
 */
static void onUI_hide() {

}

/*
 * 当界面完全退出时触发
 */
static void onUI_quit() {

}

/**
 * 串口数据回调接口
 */
static void onProtocolDataUpdate(const SProtocolData &data) {
	datas = data;
}

/**
 * 定时器触发函数
 * 不建议在此函数中写耗时操作，否则将影响UI刷新
 * 参数： id
 *         当前所触发定时器的id，与注册时的id相同
 * 返回值: true
 *             继续运行当前定时器
 *         false
 *             停止运行当前定时器
 */
static bool onUI_Timer(int id){
	switch (id) {

		default:
			break;
	}
    return true;
}

/**
 * 有新的触摸事件时触发
 * 参数：ev
 *         新的触摸事件
 * 返回值：true
 *            表示该触摸事件在此被拦截，系统不再将此触摸事件传递到控件上
 *         false
 *            触摸事件将继续传递到控件上
 */
static bool onvalveActivityTouchEvent(const MotionEvent &ev) {
    switch (ev.mActionStatus) {
		case MotionEvent::E_ACTION_DOWN://触摸按下
			//LOGD("时刻 = %ld 坐标  x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
			break;
		case MotionEvent::E_ACTION_MOVE://触摸滑动
			break;
		case MotionEvent::E_ACTION_UP:  //触摸抬起
			break;
		default:
			break;
	}
	return false;
}


static bool onButtonClick_Button25(ZKButton *pButton) {
    LOGD(" ButtonClick Button25 !!!\n");
    AddStr("1");
    return false;
}

static bool onButtonClick_Button26(ZKButton *pButton) {
    LOGD(" ButtonClick Button26 !!!\n");
    AddStr("2");
    return false;
}

static bool onButtonClick_Button27(ZKButton *pButton) {
    LOGD(" ButtonClick Button27 !!!\n");
    AddStr("3");
    return false;
}

static bool onButtonClick_Button28(ZKButton *pButton) {
    LOGD(" ButtonClick Button28 !!!\n");
    AddStr("4");
    return false;
}

static bool onButtonClick_Button29(ZKButton *pButton) {
    LOGD(" ButtonClick Button29 !!!\n");
    AddStr("5");
    return false;
}

static bool onButtonClick_Button30(ZKButton *pButton) {
    LOGD(" ButtonClick Button30 !!!\n");
    AddStr("6");
    return false;
}

static bool onButtonClick_Button31(ZKButton *pButton) {
    LOGD(" ButtonClick Button31 !!!\n");
    AddStr("7");
    return false;
}

static bool onButtonClick_Button32(ZKButton *pButton) {
    LOGD(" ButtonClick Button32 !!!\n");
    AddStr("8");
    return false;
}

static bool onButtonClick_Button33(ZKButton *pButton) {
    LOGD(" ButtonClick Button33 !!!\n");
    AddStr("9");
    return false;
}

static bool onButtonClick_Button34(ZKButton *pButton) {
    LOGD(" ButtonClick Button34 !!!\n");
    AddStr("0");
    return false;
}

static bool onButtonClick_Button35(ZKButton *pButton) {
    LOGD(" ButtonClick Button35 !!!\n");
    if(PassWard == PassWardUser){
    	mWindow1Ptr->hideWnd();
    }
    return false;
}

static bool onButtonClick_Button36(ZKButton *pButton) {
    LOGD(" ButtonClick Button36 !!!\n");
    DelStr();
    return false;
}
static bool onButtonClick_Button37(ZKButton *pButton) {
    LOGD(" ButtonClick Button37 !!!\n");
//    mWindow2Ptr->showWnd();
    Global::Flags::IsCodeFalg=true;
    return false;
}


static bool onButtonClick_Button39(ZKButton *pButton) {
    LOGD(" ButtonClick Button39 !!!\n");
    Global::Flags::IsCodeFalg=false;
    return false;
}
static bool onButtonClick_Button11(ZKButton *pButton) {
    LOGD(" ButtonClick Button11 !!!\n");
    return false;
}

static bool onButtonClick_Button19(ZKButton *pButton) {
    LOGD(" ButtonClick Button19 !!!\n");

    return false;
}

static bool onButtonClick_Button23(ZKButton *pButton) {
    LOGD(" ButtonClick Button23 !!!\n");
    EASYUICONTEXT->closeActivity("valveActivity");
    EASYUICONTEXT->showStatusBar();
    return false;
}

static bool onButtonClick_Button2(ZKButton *pButton) {
    LOGD(" ButtonClick Button2 !!!\n");
    return false;
}

static bool onButtonClick_Button10(ZKButton *pButton) {
    LOGD(" ButtonClick Button10 !!!\n");
    pButton->setSelected(!pButton->isSelected());
    if(pButton->isSelected()){
        protocol::setCold220V(true);
    	pButton->setText("废水阀:1");
    }
    else{
        protocol::setCold220V(false);
    	pButton->setText("废水阀:0");
    }
    return false;
}

static bool onButtonClick_Button7(ZKButton *pButton) {
    LOGD(" ButtonClick Button7 !!!\n");
    pButton->setSelected(!pButton->isSelected());
    if(pButton->isSelected()){
    	protocol::setWasteWater(true);
    	pButton->setText("废水阀:1");
    }
    else{
    	protocol::setWasteWater(false);
    	pButton->setText("废水阀:0");
    }
    return false;
}

static bool onButtonClick_Button6(ZKButton *pButton) {
    LOGD(" ButtonClick Button6 !!!\n");
    return false;
}

static bool onButtonClick_Button3(ZKButton *pButton) {
    LOGD(" ButtonClick Button3 !!!\n");
    return false;
}

static bool onButtonClick_Button18(ZKButton *pButton) {
    LOGD(" ButtonClick Button18 !!!\n");
    pButton->setSelected(!pButton->isSelected());
    if(pButton->isSelected()){
    	protocol::setTds(true);
    	pButton->setText("TDS1:1");
    }
    else{
    	protocol::setTds(false);
    	pButton->setText("TDS1:0");
    }
    return false;
}

static bool onButtonClick_Button21(ZKButton *pButton) {
    LOGD(" ButtonClick Button21 !!!\n");
    return false;
}

static bool onButtonClick_Button8(ZKButton *pButton) {
    LOGD(" ButtonClick Button8 !!!\n");
    pButton->setSelected(!pButton->isSelected());
    if(pButton->isSelected()){
    	protocol::setAirPump(true);
    	pButton->setText("增压泵:1");
    }
    else{
    	protocol::setAirPump(false);
    	pButton->setText("增压泵:0");
    }
    return false;
}

static bool onButtonClick_Button4(ZKButton *pButton) {
    LOGD(" ButtonClick Button4 !!!\n");
    pButton->setSelected(!pButton->isSelected());
    if(pButton->isSelected()){
        protocol::setColdWater(true);
    	pButton->setText("冷水进水阀:1");
    }
    else{
        protocol::setColdWater(false);
    	pButton->setText("冷水进水阀:0");
    }
    return false;
}

static bool onButtonClick_Button12(ZKButton *pButton) {
    LOGD(" ButtonClick Button12 !!!\n");
    return false;
}

static bool onButtonClick_Button9(ZKButton *pButton) {
    LOGD(" ButtonClick Button9 !!!\n");
    pButton->setSelected(!pButton->isSelected());
    if(pButton->isSelected()){
        protocol::setWaterIn(true);
    	pButton->setText("整机进水阀:1");
    }
    else{
        protocol::setWaterIn(false);
    	pButton->setText("整机进水阀:0");
    }
    return false;
}

static bool onButtonClick_Button15(ZKButton *pButton) {
    LOGD(" ButtonClick Button15 !!!\n");
    return false;
}

static bool onButtonClick_Button13(ZKButton *pButton) {
    LOGD(" ButtonClick Button13 !!!\n");
    pButton->setSelected(!pButton->isSelected());
    if(pButton->isSelected()){
    	protocol::ledControl(true);
    	pButton->setText("LED灯:1");
    }
    else{
    	protocol::ledControl(false);
    	pButton->setText("LED灯:0");
    }
    return false;
}

static bool onButtonClick_Button17(ZKButton *pButton) {
    LOGD(" ButtonClick Button17 !!!\n");
    return false;
}

static bool onButtonClick_Button22(ZKButton *pButton) {
    LOGD(" ButtonClick Button22 !!!\n");
    return false;
}

static bool onButtonClick_Button1(ZKButton *pButton) {
    LOGD(" ButtonClick Button1 !!!\n");
    pButton->setSelected(!pButton->isSelected());
    if(pButton->isSelected()){
    	protocol::setTds(true);
    	pButton->setText("TDS2:1");
    }
    else{
    	protocol::setTds(false);
    	pButton->setText("TDS2:0");
    }
    return false;
}

static void onEditTextChanged_EditText1(const std::string &text) {
    //LOGD(" onEditTextChanged_ EditText1 %s !!!\n", text.c_str());
}

static bool onButtonClick_Button14(ZKButton *pButton) {
    LOGD(" ButtonClick Button14 !!!\n");
    pButton->setSelected(!pButton->isSelected());
    if(pButton->isSelected()){
    	protocol::setCommonTemp(true);
    	pButton->setText("常温水阀:1");
    }
    else{
    	protocol::setCommonTemp(false);
    	pButton->setText("常温水阀:0");
    }

    return false;
}

static bool onButtonClick_Button20(ZKButton *pButton) {
    LOGD(" ButtonClick Button20 !!!\n");
    pButton->setSelected(!pButton->isSelected());
    if(pButton->isSelected()){
    	datas.inquiry_a5.output_water_control = 1;
    	pButton->setText("出水指令:1");
    }
    else{
    	datas.inquiry_a5.output_water_control = 0;
    	pButton->setText("出水指令:0");
    }
    return false;
}

static bool onButtonClick_Button40(ZKButton *pButton) {
    LOGD(" ButtonClick Button40 !!!\n");
    return false;
}

static void onEditTextChanged_EditText2(const std::string &text) {
    //LOGD(" onEditTextChanged_ EditText2 %s !!!\n", text.c_str());
}

static bool onButtonClick_Button16(ZKButton *pButton) {
    LOGD(" ButtonClick Button16 !!!\n");
    return false;
}

static bool onButtonClick_Button5(ZKButton *pButton) {
    LOGD(" ButtonClick Button5 !!!\n");
    pButton->setSelected(!pButton->isSelected());
    if(pButton->isSelected()){
    	protocol::setUVLight(true);
    	pButton->setText("热水水路回水阀:1");
    }
    else{
    	protocol::setUVLight(false);
    	pButton->setText("热水水路回水阀:0");
    }

    return false;
}


static bool onButtonClick_Button24(ZKButton *pButton) {
    LOGD(" ButtonClick Button24 !!!\n");
    EASYUICONTEXT->closeActivity("valveActivity");
    EASYUICONTEXT->showStatusBar();
    return false;
}
static bool onButtonClick_Button43(ZKButton *pButton) {
    LOGD(" ButtonClick Button43 !!!\n");
    pButton->setSelected(!pButton->isSelected());
    if(pButton->isSelected()){
    	FlagLvxin = true;
    }
    else{
    	FlagLvxin = false;
    }
    water::set_cartridge_fast_check(pButton->isSelected());
    return false;
}

static bool onButtonClick_Button45(ZKButton *pButton) {
    LOGD(" ButtonClick Button3 !!!\n");
    getProtocolParam().control_aa_a1.CmdPushRodMotorForward = true;
    return false;
}

static bool onButtonClick_Button46(ZKButton *pButton) {
    LOGD(" ButtonClick Button4 !!!\n");
    getProtocolParam().control_aa_a1.CmdPushRodMotorReverse = true;
    return false;
}

static bool onButtonClick_Button47(ZKButton *pButton) {
    LOGD(" ButtonClick Button5 !!!\n");
    getProtocolParam().control_aa_a1.CmdPushRodMotorForward = false;
    getProtocolParam().control_aa_a1.CmdPushRodMotorReverse = false;
    return false;
}

